﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BrightIdeasSoftware;

namespace GridViewDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            InitializeExamples();
        }

        void InitializeSimpleExample(List<Person> list)
        {
            //this.comboBox6.SelectedIndex = 0;

            // Give this column an aspect putter, since it fetches its value using a method rather than a property
            TypedColumn<Person> tcol = new TypedColumn<Person>(this.columnHeader16);
            tcol.AspectPutter = delegate(Person x, object newValue) { x.SetRate((double)newValue); };

            // Uncomment this to see a fancy cell highlighting while editing
            this.olvSimple.AddDecoration(new EditingCellBorderDecoration(true));

            // An example of how to do per-cell formatting

            /*
            this.olvSimple.UseCellFormatEvents = true;
            this.olvSimple.FormatCell += (sender, args) =>
            {
                // Only for the columns you want
                if (args.Column.Text != "Cooking Skill")
                    return;

                if (!(args.CellValue is int))
                    return;

                switch ((int)args.CellValue) {
                    case 1:
                        args.SubItem.BackColor = Color.Aquamarine;
                        break;
                    case 30:
                        args.SubItem.BackColor = Color.GreenYellow;
                        break;
                }
            };
            */

            // Just one line of code make everything happen.
            this.olvSimple.SetObjects(list);
        }

        List<Person> masterList;
        void InitializeExamples()
        {
            // Use different font under Vista
            if (ObjectListView.IsVistaOrLater)
                this.Font = new Font("Segoe UI", 9);

            masterList = new List<Person>();
            masterList.Add(new Person("Wilhelm Frat", "Gymnast", 21, new DateTime(1984, 9, 23), 45.67, false, "ak", "Aggressive, belligerent "));
            masterList.Add(new Person("Alana Roderick", "Gymnast", 21, new DateTime(1974, 9, 23), 245.67, false, "gp", "Beautiful, exquisite"));
            masterList.Add(new Person("Frank Price", "Dancer", 30, new DateTime(1965, 11, 1), 75.5, false, "ns", "Competitive, spirited"));
            masterList.Add(new Person("Eric", "Half-a-bee", 1, new DateTime(1966, 10, 12), 12.25, true, "cp", "Diminutive, vertically challenged"));
            masterList.Add(new Person("Nicola Scotts", "Nurse", 42, new DateTime(1965, 10, 29), 1245.7, false, "np", "Wise, fun, lovely"));
            masterList.Add(new Person("Madalene Alright", "School Teacher", 21, new DateTime(1964, 9, 23), 145.67, false, "jr", "Extensive, dimensionally challenged"));
            masterList.Add(new Person("Ned Peirce", "School Teacher", 21, new DateTime(1960, 1, 23), 145.67, false, "gab", "Fulsome, effusive"));
            masterList.Add(new Person("Felicity Brown", "Economist", 30, new DateTime(1975, 1, 12), 175.5, false, "sp", "Gifted, exceptional"));
            masterList.Add(new Person("Urny Unmin", "Economist", 41, new DateTime(1956, 9, 24), 212.25, true, "cr", "Heinous, aesthetically challenged"));
            masterList.Add(new Person("Terrance Darby", "Singer", 35, new DateTime(1970, 9, 29), 1145, false, "mb", "Introverted, relationally challenged"));
            masterList.Add(new Person("Phillip Nottingham", "Programmer", 27, new DateTime(1974, 8, 28), 245.7, false, "sj", "Jocular, gregarious"));
            masterList.Add(new Person("Mister Null"));

            List<Person> list = new List<Person>();
            foreach (Person p in masterList)
                list.Add(new Person(p));

            // Change this value to see the performance on bigger lists.
            // Each list builds about 1000 rows per second.
            //while (list.Count < 5000) {
            //    foreach (Person p in masterList)
            //        list.Add(new Person(p));
            //}

            InitializeSimpleExample(list);
        }
    }
}
